//
//  SEGOrderDetailModel.m
//  Uhomebk
//
//  Created by mac on 2017/7/5.
//  Copyright © 2017年 com.segi. All rights reserved.
//  注意set方法已修改

#import "SEGOrderDetailModel.h"

@implementation SEGOrderDetailModel
{
    NSArray * superOtherFormListData;//用来传值，到SEGOtherFormList
}

-(SEGOrderDetailModel *)addDataByDictionary:(NSDictionary *)dic
{
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
        if (self.mDictionary) {
            [self.mDictionary addEntriesFromDictionary:dic];
        }else{
            self.mDictionary = [[NSMutableDictionary alloc] initWithDictionary:dic];
        }
    }else{
        return [self initWithDictionary:dic];
    }
    return self;
}

- (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    self = [super init];
    if (self) {
        _baseInfos = [SEGOrderBaseInfoModel initWithDictionary:@{}];
        _trackInfos = [[NSArray alloc] init];
        _detailInfos = [[NSArray alloc] init];//OrderFormList子模型
        [self setValuesForKeysWithDictionary:dictionary];
        
        self.mDictionary = [[NSMutableDictionary alloc] initWithDictionary:dictionary];

    }
    return self;
}

+ (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    return [[self alloc] initWithDictionary:dictionary];
}

- (void)setValue:(id)value forUndefinedKey:(NSString*)key
{//注意此方法
    
}

-(void)setValue:(id)value forKey:(NSString *)key
{

    if ([key isEqualToString:@"formList"]) {
        
        __block NSMutableArray* _arrM = [NSMutableArray array];
        
        [value enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if([obj isKindOfClass:[SEGTemplateModel class]]){
                [_arrM addObject:obj];
            }else{
                SEGTemplateModel* model = [SEGTemplateModel initWithDictionary:obj];
                [_arrM addObject:model];
            }
        }];
        
        _detailInfos = _arrM;
        return;
    }
   
    [super setValue:value forKey:key];
 

}

@end
